package com.comm.db.jdbc;

import java.sql.*;
 

 

/**
 * ---------------
 * 
 * @author [Richie] 2008-7-14 : 下午05:59:40
 *         -------------------------------------------172.26.9.2--Intelligence/whwj6576
 *         172.26.9.5--uat/uat
 * @description 要更改此生成的类型注释的模板，请转至 窗口 － 首选项 － Java － 代码样式 － 代码模板
 */
public class JDBC {
 
	protected static Connection conn = null;

	private static String SID = "ops";//"intellig";//"intellig";// Intelligence/whwj6576

	private static String dbUser_1_0 = "root";//"Intelligence";//"Intelligence";// "QX10";

	private static String dbPassword_1_0 = "root";//"whwj6576";//"whwj6576";// "QX10" ;

 	private static String SIP = "localhost";//"172.26.9.17";

	private static String port = "3306";//"1521";

	private static String OracleDriverString = "com.mysql.jdbc.Driver";//"oracle.jdbc.driver.OracleDriver";

	/**
	 * 
	 * @return Connection
	 * @throws InstantiationException
	 * @throws IllegalAccessException
	 * @throws ClassNotFoundException
	 */
	/*
	 * protected static Connection getConnection() throws
	 * InstantiationException, IllegalAccessException, ClassNotFoundException {
	 *  // 连接池里没有可用的，空闲的连接，创建连接 createConnection(); return conn; }
	 */

	/**
	 * @title 创建连接
	 * @return
	 */
	public synchronized static Connection createConnection() {
	 	Connection _conn = null;
		try {
			Class.forName(OracleDriverString).newInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
		// SID 为你的数据库的SID
		String url = "jdbc:mysql://" + SIP + ":" + port + "/" + SID+"?characterEncoding=gbk";
		try {
			_conn = (Connection) DriverManager.getConnection(url, dbUser_1_0,
					dbPassword_1_0);

		} catch (SQLException e) { // 捕捉SQL违例
		 	System.out.println("Ora10iConnect在连接oracle10I数据库时捕获");
			e.printStackTrace();
			while (e != null) {
			 
				e = e.getNextException();
			 
			}
			_conn = null;
		}
		 
	 	//conn = _conn;
		return _conn;
	}

	/**
	 * @title 创建连接
	 * @return
	 */
	public synchronized static Connection createConnection(String QX20) {
		Connection _conn = null;
		try {
			Class.forName(OracleDriverString).newInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
		// SID 为你的数据库的SID
		String url = "jdbc:mysql://" + SIP + ":" + port + "/" + SID+"?characterEncoding=utf8";
		 
		conn = _conn;
		return _conn;
	}
	/** *//**
     * 使程序等待给定的毫秒数
     * wait(5000); // 等 5 秒  60000=1分钟
     * @param 给定的毫秒数
     */
    protected static void  wait(int mSeconds)
    {
        try
        {
        	Thread.sleep(mSeconds);
        } catch (InterruptedException e)
        {
        }
    }
	public static void main(String[] args) throws Exception {
		conn = createConnection();
		System.out.println(conn.getMetaData());
		System.out.println(conn.getAutoCommit());
	}

}
